package com.seu.nic.component.crontab;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class CustomThreadFactory implements ThreadFactory {
    private static final AtomicInteger poolNumber = new AtomicInteger(1);
    private final int threadNumber = poolNumber.getAndIncrement();
    private final AtomicInteger threadCounter = new AtomicInteger(1);
    private final String namePrefix;

    public CustomThreadFactory() {
        this.namePrefix = "CRONTAB-ADC-" + threadNumber + "-thread-";
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(r, namePrefix + threadCounter.getAndIncrement());
        // 设置线程为守护线程（可选）
        // thread.setDaemon(true);
        // 设置线程的优先级（可选）
        // thread.setPriority(Thread.NORM_PRIORITY);
        return thread;
    }
}